package com.itheima.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * 响应数据和结果视图
 */
@Controller
@RequestMapping(value = "/responseData")
public class ResponseData {


    /**
     * modelAndView 学习
     * @return
     */
    @RequestMapping(value = "/modelAndViewTest")
    public ModelAndView modelAndViewTest()
    {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("name", "yanweifeng");
        modelAndView.addObject("year", 21);
        modelAndView.setViewName("modelAndViewTest");
        return modelAndView;
    }


    /**
     * 转发测试
     * @return
     */
    @RequestMapping(value = "forwardTest")
    public String forwardTest()
    {
        System.out.println("执行了 forward 方法");
        return "forward:/WEB-INF/pages/success.jsp";
    }

    /**
     * 测试重定向
     * @return
     */
    @RequestMapping(value = "redirectTest")
    public String redirectTest()
    {
        System.out.println("执行了 redirectTest 方法");
        return "redirect:/responseData/forwardTest";
    }


}
